#!/bin/bash
# $Id$

wd="`pwd`"
. $wd/env

DSKSZ="20G"

# root
if [ "$UID" != "0" ]; then
	echo "Must run as root!! "
	exit 1
fi

if [ ! -f $wd/tmp/hda.img ]; then
	qemu-img create -f qcow2 $wd/tmp/hda.img $DSKSZ
fi
if [ ! -f $wd/tmp/hdb.img ]; then
	qemu-img create -f qcow2 $wd/tmp/hdb.img $DSKSZ
fi
if [ ! -f $wd/tmp/sda.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sda.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdb.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdb.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdc.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdc.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdd.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdd.img $DSKSZ
fi
if [ ! -f $wd/tmp/sde.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sde.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdf.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdf.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdg.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdg.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdh.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdh.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdi.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdi.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdj.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdj.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdk.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdk.img $DSKSZ
fi
if [ ! -f $wd/tmp/sdl.img ]; then
	qemu-img create -f qcow2 $wd/tmp/sdl.img $DSKSZ
fi

if [ "$slackware_arch" = "x86_64" ]; then
	iso=mostaza64.iso
else
	iso=mostaza.iso
fi

if [ ! -f $wd/$iso ]; then
	echo "ERROR: there is no $wd/$iso image !!"
	exit 1
fi

echo -n " Boot CD(d) or HD(c) ?: "
read ans
if [ "$ans" = "d" ]; then
	boot=d
elif [ "$ans" = "c" ]; then
	boot=c
fi

chmod 750 $wd/files/qemu-ifup

#-kernel-kqemu \
#qemu 	-nographic -cdrom ./mostaza.iso \
#qemu 	-std-vga -cdrom ./mostaza.iso \
#qemu 	-vnc :1 -cdrom ./mostaza.iso \
echo "Starting qemu..."
qemu 	-cdrom ./mostaza.iso \
	-hda $wd/tmp/hda.img -hdb $wd/tmp/hdb.img \
	-net nic,model=e1000,vlan=0 -net tap,vlan=0,ifname=tap0,script=$wd/files/qemu-ifup \
	-drive file=$wd/tmp/sda.img,if=scsi,bus=0,unit=0 \
	-drive file=$wd/tmp/sdb.img,if=scsi,bus=0,unit=1 \
	-drive file=$wd/tmp/sdc.img,if=scsi,bus=0,unit=2 \
	-drive file=$wd/tmp/sdd.img,if=scsi,bus=0,unit=3 \
	-drive file=$wd/tmp/sde.img,if=scsi,bus=0,unit=4 \
	-drive file=$wd/tmp/sdf.img,if=scsi,bus=0,unit=5 \
	-drive file=$wd/tmp/sdg.img,if=scsi,bus=1,unit=0 \
	-drive file=$wd/tmp/sdh.img,if=scsi,bus=1,unit=1 \
	-drive file=$wd/tmp/sdi.img,if=scsi,bus=1,unit=2 \
	-drive file=$wd/tmp/sdj.img,if=scsi,bus=1,unit=3 \
	-drive file=$wd/tmp/sdk.img,if=scsi,bus=1,unit=4 \
	-drive file=$wd/tmp/sdl.img,if=scsi,bus=1,unit=5 \
       	-boot $boot -m 256


